package logics
{
	import global.Global;
	import global.Managers;
	import global.TableState;
	import global.WorldType;
	
	import net.servers.ServerManager;
	
	import ui.faces.FaceManager;
	import ui.prompt.PromptBox;
	
	import worlds.BaseWorld;
	
	public class TableManager
	{
		private var _id						: int;
		
		public var state					: int = TableState.IDLE;
				
		public function get id():int {
			return _id;
		}
		
		public function TableManager()
		{
		}
		public function init(serverManager:ServerManager):void {
			_id = int(Global.config.TableID.toString());
			
			serverManager.subscribe("ChangeState", changeStateHandler);
			
			serverManager.send("ID", {state:state, id:_id});
		}
		private function changeStateHandler(data:Object):void {
			// 只有餐桌客户端才可以有状态转换
			if(BaseWorld.worldType != WorldType.TABLE_WORLD) return;
			var state:int = data.state;
			if(state == this.state) return;
			this.state = state;
			// 根据改变为的状态调整显示界面
			var faceManager:FaceManager = Managers.faceManager;
			switch(state) {
				case TableState.IDLE:
					faceManager.switchTo(faceManager.idleFace);
					break;
				case TableState.WORK:
					faceManager.switchTo(faceManager.mainFace);
					break;
				case TableState.PAY_BILL:
					PromptBox.attention(Managers.languageManager.getLanguageText("apply_pay_waiting_tip"));
					break;
			}
		}
	}
}